package com.example.qxfw.qxybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.qxybzz.entity.SmallScaleStation;
import com.example.qxfw.qxybzz.entity.admincode;
import com.example.qxfw.qxybzz.service.CommonService;
import com.example.qxfw.qxybzz.service.MeteorologyMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 14559
 * @version 1.0
 * @description: TODO
 * @date 2024/12/12 17:40
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/qxybzzCommon")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @Autowired
    private MeteorologyMaterialsService MeteorologyMaterialsService;

    /***
     * 得到城市和区县
     * @param
     * @return
     */
    @RequestMapping("/getCountys")
    public SysResult getCountys(String advcode) {
        if (advcode == null || advcode == "")
            return SysResult.fail("传入参数为空！");
        List<admincode> list = commonService.getCountys(advcode);
        return SysResult.success(list);
    }

    /***
     * 得到行政区划下的站点
     * @param advname
     * @return
     */
    @RequestMapping("/getCountyStation")
    public SysResult getCountyStation(String advname) {
        if (advname == null || advname == "")
            return SysResult.fail("传入参数为空！");
        List<SmallScaleStation> list = commonService.getCountyStation(advname);
        List<SmallScaleStation> tourStation = MeteorologyMaterialsService.getTourStation(advname);
        List<SmallScaleStation> traffcStation = MeteorologyMaterialsService.getTrafficStation(advname);
        List<SmallScaleStation> allStation =new ArrayList<>();
        allStation.addAll(list);
        allStation.addAll(tourStation);
        allStation.addAll(traffcStation);
        return SysResult.success(allStation);


//        return SysResult.success(list);
    }
}
